package com.songcha.module_bookreader.ui.activity.sdcard_novel_select

import android.app.Application
import com.songcha.library_base.mvvm.base.BaseViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import java.io.File

class SDCardNovelSelectViewModel(app:Application):BaseViewModel<SDCardNovelSelectRepository>(app) {
    val novelList = MutableStateFlow<List<String>>(listOf())

    fun getData(){
        val path = getApplication<Application>().getExternalCacheDir()!!.getAbsolutePath() + "/"
        val files = File(path).listFiles()
        val list = mutableListOf<String>()
        for(item in files){
            if(item.isFile && item.name.endsWith(".txt")){
                list.add(item.name.substring(0,item.name.length - 4))
            }
        }
        novelList.value = list
    }
}